/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mb.webserver.inMemory;

import mb.config.Constants;
import mb.config.ConstantsMsg;
import mb.mbmiddle.MbPartMiddle;
import mb.mbpart.memory.BaseMemory;
import static mb.webserver.inMemory.BaseProcess.nTotal;

/**
 *
 * @author thanh.nguyenchi
 */
public class ServiceDetailProcess extends BaseProcess{ 
    int status;
    String error;
    String lang;
    String serviceId;
    String services;    // array 

    public ServiceDetailProcess(String lang,String serviceId){
        this.lang = lang;
        this.serviceId = serviceId;
        process();
    }
    
    @Override
    public void process(){
        String memKey = Constants.STR_MEM_SERVIES + Constants.STR_ID_CODE + serviceId;
        // lay du lieu        
        BaseMemory objMem = (BaseMemory)MbPartMiddle.objMemory.get(memKey);
        if (objMem != null){            
            status = ConstantsMsg.INT_SUCESSFUL_CODE;
            error = "";   
            services = objMem.getData();
        }
        else{
            status = ConstantsMsg.INT_NO_DATA_FOUND;
            error = ConstantsMsg.getErrMsg(status,lang);
        }
        return;
    }
    
    @Override
    public String toJson(){ 
        String sResult = "";
        sResult = sResult + "{\"" + nStatus + "\":" + status;
        sResult = sResult + ",\"" + nError + "\":\"" + error + "\"";
        sResult = sResult + ",\"" + nNews + "\":" + services;
        sResult = sResult + ",\"" + nTotal + "\":" + 0;
        sResult = sResult + "}";
        return sResult;
    }
        
}
